package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.domain.SystemDictionary;
import cn.wolfcode.rbac.mapper.DepartmentMapper;
import cn.wolfcode.rbac.mapper.SystemDictionaryMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IDepartmentService;
import cn.wolfcode.rbac.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {
    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo query(QueryObject qo) {
        /*Integer rows = Integer.valueOf(this.departmentMapper.selectForCount(paramQueryObject));
        if (rows.intValue()==0){
            return new PageResult(Integer.valueOf(paramQueryObject.getPageSize()));
        }
        List<Department> list = this.departmentMapper.selectForList(paramQueryObject);
        return new PageResult(Integer.valueOf(paramQueryObject.getCurrentPage()),rows,list,Integer.valueOf(paramQueryObject.getPageSize()));*/
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionary> list = this.systemDictionaryMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(SystemDictionary entity) {
        if(entity.getId()==null){
            this.systemDictionaryMapper.insert(entity);
        }else {
            this.systemDictionaryMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public void delete(Long paramLong) {
        this.systemDictionaryMapper.deleteByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public SystemDictionary get(Long paramLong) {
        return this.systemDictionaryMapper.selectByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public List<SystemDictionary> list() {
        return this.systemDictionaryMapper.selectAll();
    }


}
